<template>
	<view>
		
		<view class="form">
			
			<view class="form-item u-border-bottom" style="display: flex; align-items: center;">
				<text class="form-title" style="line-height: 1.5;">营业执照\n格式png、jpg\n大小限制50MB。</text>
				<view style="display: flex; flex-direction: row; justify-content: flex-end; flex: 1;">
					<u-upload
						max-count="1" 
						:file-list="filelist"
						@on-uploaded="uploaded"
						@on-remove="onRemove"
						:action="action" 
						style="marign:-10rpx; background-color: #F2F2F2; border-radius: 10rpx; margin-top: 30rpx;">
					</u-upload>
				</view>
			</view>
			
			<view class="form-item u-border-bottom">
				<text class="form-title">公司</text>
				<u-input style="flex: 1;" :customStyle="inputStyle" v-model="business" :disabled="true" input-align="right" placeholderStyle="color: #fff"></u-input>
			</view>
			
		</view>
		
		<u-button @click="submit" :ripple="true" :customStyle="{
			margin:'32rpx',
			height:'90rpx',
			backgroundColor:'#2e8bf0',
			color:'#FFFFFF'
		}">提交</u-button>
	</view>
</template>
<style>
	page{
		background-color: #FFFFFF;
	}
	.form{ display: flex; flex-direction: column; margin-top: 16rpx; } 
	.form-item{ display: flex; flex-direction: row; margin:0 32rpx; background-color: #FFFFFF; padding: 0 30rpx; }
	.form-title{ font-size: 24rpx; line-height: 110rpx; margin-right: 30rpx;}
	input:focus::-moz-placeholder {
	color:#fff;
	}
</style>
<script>
	export default {
		data() {
			return {
				inputStyle:{
					height:'110rpx',
					fontSize:'24rpx',
					flex:'1',
					width:'100%'
				},
				
				
				action:this.$u.http.config.host + '/api.php/user/upload/one?app=business',
				filelist:[], 
				business:"",
				image:""
			}
		},
		onLoad(){
			//用户信息
			this.$u.api.getUserInfo().then(res => {
				this.business = res.data.business;
				if(res.data.business_image_url){
						this.filelist.push({
							url:res.data.business_image_url
						});
				}
				
				this.image = res.data.business_image;
				this.avatar = res.data.avatar;
			});
		},
		methods: {
			uploaded(list,name){ 
				console.log(list);
				let image = [];  
				console.log(list[0].response.data.license.words_result['单位名称']);
				this.image = list[0].response.data.filepath;
				if(list[0].response.data.license){
					if(list[0].response.data.license.words_result){
						this.business = list[0].response.data.license.words_result['单位名称'].words;
						console.log(this.business);
					}
				}
				
			},
			onRemove(a,b,c){ 
				this.image = "";
				this.business = "";
			},
			submit(){
				if(!this.image){
					this.$u.toast('请上传营业执照');
					return false;
				}
				if(!this.business){
					this.$u.toast('请上传正确营业执照');
					return false;
				}
				
				this.$u.api.postUserInfo({
					business_image:this.image,
					business:this.business
				}).then(res => {
					this.$u.toast(res.msg); 
				});
				
			}
		}
	}
</script>

<style>

</style>
